{#
# This file is part of Zenodo.
# Copyright (C) 2015, 2017 CERN.
#
# Zenodo is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Zenodo is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Zenodo; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307, USA.
#
# In applying this license, CERN does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.
-#}

{%- extends "invenio_accounts/login_user.html" %}

{% macro safe_render_field(field, icon="", autofocus=False, errormsg=True, size="form-group-lg") %}
  <div class="form-group {{size}}{% if icon %} has-feedback{% endif %}{% if field.errors and errormsg %} has-error{% endif %}">
    {%- set extras = dict(autofocus="") if autofocus else dict() %}
    {{field(class_="form-control", placeholder=_(field.label.text | string), **extras)}}
    {%- if icon %}
    <i class="{{icon}} form-control-feedback" aria-hidden="true" ></i>
    {%- endif%}
  </div>
  {%- if field.errors and errormsg %}
  <div class="text-danger text-left" role="alert">
    {%- for error in field.errors %}
    <p>{{error}}</p>
    {%- endfor %}
  </div>
  {%- endif %}
{% endmacro %}

{%- block form_outer %}
  <div class="social-signup">
    <a href="{{url_for('invenio_oauthclient.login', remote_app='github', next=(request.args.get('next') or request.referrer))}}" class="btn btn-default btn-lg btn-block"><i class="fa fa-github"></i> {{_('Log in with GitHub')}}</a>
    <a href="{{url_for('invenio_oauthclient.login', remote_app='orcid', next=(request.args.get('next') or request.referrer))}}" class="btn btn-default btn-lg btn-block"><img src="{{ url_for('static', filename='img/orcid.svg')}}" height="18px"> {{_('Log in with ORCID')}}</a>
    <h3 align="center">&mdash; OR &mdash;</h3>
  </div>
  {%- with form = login_user_form %}
    <form action="{{ url_for_security('login') }}" method="POST" name="login_user_form">
      {{ form.hidden_tag() }}
      {{ form_errors(form) }}
      {{ safe_render_field(form.email, icon="fa fa-user", autofocus=True, errormsg=False) }}
      {{ safe_render_field(form.password, icon="fa fa-lock", errormsg=False) }}
      <button type="submit" class="btn btn-primary btn-lg btn-block"><i class="fa fa-sign-in"></i> {{_('Log In')}}</button>
    </form>
  {%- endwith %}
{%- endblock %}

{%- block registerable %}
{%- if security.registerable %}
<div class="panel-footer text-center">
    <h4 class="text-muted">{% trans sitename=config.ACCOUNTS_SITENAME %}New to {{sitename}}?{% endtrans %} <a href="{{url_for('security.register')}}">{{_('Sign Up')}}</a></h4>
    <a href="https://about.zenodo.org/privacy-policy/">{{_('Privacy notice')}}</a>
</div>
{%- endif %}
{%- endblock %}

{%- block recoverable %}
<footer>{{super()}}
</footer>
{%- endblock %}
